<template>

	<div class="tra-shu-xue-sheng-qing-edit">
		<MkBillPanel4ShenQing :bill="ctx.traShenQing" ref='billPanelRef' createUserNameLabel="开单医生"
			createTimeLabel="开单时间">
			<template #button>
				<MkButtonQueryHistory @click="listRef.open()" />
				<MkButtonAdd @click="newEntity" :isEdit="ctx.isEdit" />
				<MkButtonSubmit @click="submit" :loading="ctx.loading" :isEdit="ctx.isEdit" />
				<AuditButton title="上级医生审核" :traShenQingHuanZhe="ctx.traShenQingHuanZhe" @audit="shangJiShenHe"
					:disabled="ctx.traShenQing.danJuZhuangTai != enumCode.Djzt_ShuXueShenQing.待上级审核" />
				<AuditButton title="输血科审核" :traShenQingHuanZhe="ctx.traShenQingHuanZhe" @audit="shuXueKeShenHe"
					:disabled="ctx.traShenQing.danJuZhuangTai != enumCode.Djzt_ShuXueShenQing.待输血科审核" />
				<MkButtonMore>
					<a-menu-item @click="edit">修改</a-menu-item>
					<a-menu-item @click="cancel">作废</a-menu-item>
					<a-menu-item @click="billPanelRef.showCaoZuo()">操作记录</a-menu-item>
				</MkButtonMore>
				<MkButtonMore title="打印申请单" @click="test" icon="ele-Printer">
					<a-menu-item @click="print">打印申请单</a-menu-item>
					<a-menu-item @click="printTongYiShu">打印同意书</a-menu-item>
				</MkButtonMore>
			</template>
			<template #info>
				<MkPanel title="">
					<MkForm :model='ctx.traShenQing' ref='formRef' :col="4">
						<MkSelectUser label='申请医生' v-model='ctx.traShenQing.createUserName' prop='createUserName'
							:isEdit='false' />
						<MkSelectUser label='上级医生' v-model='ctx.traShenQing.shangJiShenHeRenId'
							prop='shangJiShenHeRenId' :isEdit='false' />
						<MkSelectUser label='科主任' v-model='ctx.traShenQing.keZhuRenShenHeRenId'
							prop='keZhuRenShenHeRenId' :isEdit='false' />
						<MkSelectUser label='输血科' v-model='ctx.traShenQing.shuXueKeShenHeRenId'
							prop='shuXueKeShenHeRenId' :isEdit='false' />
					</MkForm>
				</MkPanel>
			</template>
			<div class="edit-info">
				<div class="edit-info-left">
					<!-- 患者信息 -->
					<EditHuanZhe ref="editHuanZheRef" v-model="ctx.traShenQingHuanZhe" :isEdit="ctx.isEdit"
						@getPatientSuccess="getPatientSuccess" @editPatientInfo="editPatientInfo" />
					<!-- 用血信息 -->
					<EditYongXue ref="editYongXueRef" v-model="ctx.traShenQingYongXue" :isEdit="ctx.isEdit" />
					<!-- 评估信息 -->
					<EditShuXueQianPingGu v-model="ctx.traShenQingHuanZhe" :pingGuInput="ctx.pingGuInput"
						:isEdit="ctx.isEdit" />
				</div>
				<div class="dividebox" ref="divideRef" v-resize="['.edit-info-left', '.edit-info-right']"></div>
				<div class="edit-info-right">
					<!-- 复核信息 -->
					<EditHuanZheFuHe v-model="ctx.traShenQingHuanZhe" />
					<!-- 输血前检验 -->
					<EditShuXueQianJianYan v-model="ctx.traShenQingJianYanList" />
				</div>
			</div>
		</MkBillPanel4ShenQing>
		<ListPage ref='listRef' @load='loadEntity' />
	</div>

</template>
<script lang="ts" setup name="traShuXueShengQing">
// 输血申请模块--编辑
import { watch } from 'vue';
import ListPage from './list.vue';
import { clog } from '/@/utils';
import { enumCode } from '/@/const';

import EditHuanZhe from './editHuanZhe.vue';
import EditYongXue from './editYongXue.vue';
import EditShuXueQianPingGu from './editShuXueQianPingGu.vue';
import EditShuXueQianJianYan from './editShuXueQianJianYan.vue';
import EditHuanZheFuHe from './editHuanZheFuHe.vue'
import AuditButton from './auditButton.vue';
import {
	ctx,
	editHuanZheRef, editYongXueRef, listRef, billPanelRef, caoZuoRef,
	newEntity, loadEntity, submit, cancel, edit,
	print, printTongYiShu,
	shangJiShenHe, shuXueKeShenHe
} from './index'

const test = () => {
	clog('shenQingYongXue:', ctx.traShenQingYongXue);
}

const getPatientSuccess = () => {
	ctx.traShenQingYongXue.shenQingABO = ctx.traShenQingHuanZhe.chuShaiABO
	ctx.traShenQingYongXue.shenQingRhD = ctx.traShenQingHuanZhe.chuShaiRhD

	// 用患者Id作入参,异步调用接口平台,获取检验结果
	// ctx.traShenQingHuanZhe.huanZheId;

	// 模拟数据
	ctx.traShenQingJianYanList = [
		{ mingCheng: 'HCT', jieGuo: '500', danWei: '%', jianYanShiJian: '2025-06-18 15:15' },
		{ mingCheng: 'HB', jieGuo: '50', danWei: '', jianYanShiJian: '2025-06-18 15:15' },
		{ mingCheng: 'PLT', jieGuo: '80', danWei: 'x10^9/L', jianYanShiJian: '2025-06-12 15:15' },
		{ mingCheng: '凝血酶时间', jieGuo: '19.5', danWei: '', jianYanShiJian: '2025-05-11 16:15' },
		{ mingCheng: '凝血酶原时间', jieGuo: '12.5', danWei: '', jianYanShiJian: '2025-06-18 15:15' },
		{ mingCheng: '不规则抗体', jieGuo: '阳', danWei: '', jianYanShiJian: '2025-06-13 15:15' },
		{ mingCheng: 'HIV抗体', jieGuo: '阴', danWei: '', jianYanShiJian: '2025-06-18 15:15' },
		{ mingCheng: '血小板抗休检测', jieGuo: '', danWei: '', jianYanShiJian: '' },
		{ mingCheng: 'APT', jieGuo: '30', danWei: 's', jianYanShiJian: '2025-06-18 15:15' },
		{ mingCheng: '梅毒', jieGuo: '', danWei: '', jianYanShiJian: '' },
		{ mingCheng: 'HBsAg', jieGuo: '', danWei: 'ml', jianYanShiJian: '2025-06-18 15:15' },
		{ mingCheng: '谷丙转氨酶', jieGuo: '', danWei: '', jianYanShiJian: '' },
	]

	// 初始化 ctx.pingGuInput
	ctx.pingGuInput = {} as PingGuInput;

	// 循环 traShenQingJianYanList，将 mingCheng 值作为属性，jieGuo 值作为相应的值添加到 ctx.pingGuInput 中
	ctx.traShenQingJianYanList.forEach(item => {
		ctx.pingGuInput[item.mingCheng] = item.jieGuo;
	});
}
/** 弹框修改患者信息回调 */
const editPatientInfo = () => {
	ctx.traShenQingYongXue.shenQingABO = ctx.traShenQingHuanZhe.chuShaiABO
	ctx.traShenQingYongXue.shenQingRhD = ctx.traShenQingHuanZhe.chuShaiRhD
}

</script>
<style lang="scss" scoped>
@use './css/index.scss';
</style>
